var API_ROOT = "http://test.api.muzhibuluo.com/api/imusic_s07e01/";
//var AUTH_URL = "http://test.m.muzhibuluo.com/auth/weibo/login";
var AUTH_URL = "http://test.m.muzhibuluo.com/auth/anonymous/login";

var JSSKD_URL = "http://test.m.muzhibuluo.com/auth/wechat/jssdk";
var API_DEBUG = "";
var SITE_ID = "1258238806";
window.shareObj = {
    title:"我参加了爱音乐春季运动会，拿到100元话费，数量有限，快来",
    decstr:"爱音乐给你献上100元三网话费",
    linkstr:function(){
        var arr = window.location.href.split("/");
        arr[arr.length-1] = "startup.html";
        return arr.join("/");
    }(),
    iconstr:function(){
        var arr = window.location.href.split("/");
        arr[arr.length-1] = "image/shareicon.png";
        return arr.join("/");
    }()
};

$.ajax({
    url:JSSKD_URL+'?originalUrl='+encodeURIComponent(location.href.split('#')[0])+'&datetime='+new Date().getTime(),
    async:false,
    dataType:"json",
    success:function(data){
        window.jssdk = data.jssdk;
    },
    error:function(){
        alert("获取jssdk失败");
    }
});
if (!window.localStorage.getItem("mz_jwt")) {
    //$.ajax({
    //    url: AUTH_URL + '?gamesRedirectUri=' + encodeURIComponent(location.href.split('#')[0]) + '&datetime=' + new Date().getTime(),
    //    type: "POST",
    //    async: false,
    //    success: function (data) {
    //        ret = data;
    //        console.log('location.href', location.href);
    //        if (data.result === 'error') {
    //            console.log('login error', data.errmsg);
    //        } else if (data.result === 'unauth') {
    //            console.log('login unauth', data.url);
    //            location.href = data.url;
    //        } else {
    //            console.log('logined', data);
    //            console.log('current wechat user', data.user);
    //            var user = data.user;
    //            myOpenId = user.openid;
    //            /*$$Client.headImgUrl = user.headimgurl;
    //             username = user.nickname;*/
    //            window.localStorage.setItem("mz_jwt", data.mz_jwt);
    //            mz_jwt = data.mz_jwt;
    //            console.log(mz_jwt);
    //            $.ajaxSetup({
    //                beforeSend: function (xhr) {
    //                    xhr.setRequestHeader("Authorization", "Bearer " + data.mz_jwt);
    //                }
    //            });
    //        }
    //    },
    //    error: function () {
    //        alert("初始化失败");
    //    }
    //});
} else {
    $.ajaxSetup({
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "Bearer " + window.localStorage.getItem("mz_jwt"));
        }
    });
}
